package dao

import (
	"zk2zc/inits"
	"zk2zc/model"
	"zk2zc/until"
)

func GetUserByUsername(username string) (result *model.User, err error) {
	if err = inits.DB.Where("username=?", username).Find(&result).Error; err != nil {
		return nil, err
	}
	return result, nil
}
func CreateUser(username string, password string) (err error) {
	result := model.User{
		Username: username,
		Password: until.MD5(password),
	}
	if err = inits.DB.Create(&result).Error; err != nil {
		return err
	}
	return nil
}
func GetUser() (result *model.User, err error) {
	if err = inits.DB.Find(&result).Error; err != nil {
		return nil, err
	}
	return result, nil
}
